﻿using Host;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AXImServer
{
    public class FriendComponent : IComponents
    {
        public IFriendService FriendService { get; set; }

        /// <summary>
        /// 获取用户的全部好友
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        [IComponentsMethod]
        public CallBackStatusData GetAllFriend()
        {
            return new CallBackStatusData<IEnumerable<Friend.Friend>> { StatusCode = StatusCode.Success, Data = FriendService.GetAllByFilter(null) };
        }

        /// <summary>
        /// 创建好友关系
        /// </summary>
        /// <param name="token"></param>
        /// <param name="friendid"></param>
        /// <returns></returns>
        [IComponentsMethod]
        public CallBackStatusData CreateFriend(long friendid)
        {
            var user = LoginManager.GetInstance().GetCurrentUser();
            FriendService.Add(new Friend.Friend { UserId = user.UserId, FriendId = friendid });

            //向对方发起请求

            return CallBackStatusDataEx.Success();
        }
    }
}
